package com.feri.pm.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feri.pm.dao.SysRoleDao;
import com.feri.pm.dao.SysUserRoleDao;
import com.feri.pm.entity.SysRole;
import com.feri.pm.service.intf.SysRoleService;
import com.feri.pm.util.AuthUtil;
import com.feri.pm.vo.R;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * 17.角色表(SysRole)表服务实现类
 *
 * @author makejava
 * @since 2023-03-26 10:40:28
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Resource
    private SysRoleDao dao;
    @Resource
    private SysUserRoleDao userRoleDao;

    @Override
    public R add(String name) {
        if(StringUtils.hasLength(name)){
            if(dao.insert(new SysRole(name))>0){
                return R.ok();
            }
        }
        return R.fail();
    }

    @Override
    public R all() {
        return R.ok(dao.selectList(null));
    }

    @Override
    public R updateByUid(int rid) {
        //修改数据库
        if(userRoleDao.udpateByUid(AuthUtil.getUid(),rid)>0){
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public R queryPage(int page, int size) {
        return R.ok(dao.selectPage(new Page<>(page,size),null));
    }
}

